package com.guashu.springbootasynchronous.async.AsyncThread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 1、线程实现异步
 */
@Slf4j
public class AsyncThread extends Thread {
    private ExecutorService executorService = Executors.newCachedThreadPool();

    public void fun() {
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    sleep(9000);
                    log.info("睡9秒后，处理异步处理完成.");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
        });
    }

    public static void main(String[] args) {
        AsyncThread asyncThread = new AsyncThread();
        asyncThread.fun();
        System.out.println("当前线程:" + Thread.currentThread().getName() + " 接口直接返回!");
    }
}